package com.example.parking;

import com.example.parking.entity.ParkingSpace;
import com.example.parking.entity.Vehicle;
import com.example.parking.repository.ParkingSpaceRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DataInitializer {
    @Bean
    public CommandLineRunner initData(ParkingSpaceRepository repository) {
        return args -> {
            // 初始化一些车位
            repository.save(new ParkingSpace("A001", "A区", "空闲", null));
            repository.save(new ParkingSpace("A002", "A区", "空闲", null));
            repository.save(new ParkingSpace("B001", "B区", "空闲", null));

            // 初始化一个已占用的车位
            Vehicle vehicle = new Vehicle("京A12345", "张三");
            ParkingSpace occupiedSpace = new ParkingSpace("C001", "C区", "已占用", vehicle);
            repository.save(occupiedSpace);
        };
    }
}